{include file='/public/header'}

<div class="am-cf admin-main">
    {include file='/public/sidebar'}

    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">编辑文档</strong> / <small>edit doc</small></div>
            </div>

            <hr/>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-4 am-u-md-push-8"></div>

                <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
                    <form class="am-form am-form-horizontal" id="ajax-form" action="{:url('/admin/doc/edit')}" method="post" data-am-validator>
                        <input type="hidden" name="id" value="{$info['id']}" />
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">所属分类</label>
                            <div class="am-u-sm-9">
                                <select id="top_categories" data-am-selected="{btnWidth:'49%',btnSize:'md'}">
                                    {foreach $top_categories as $category}
                                    <option value="{$category.id}" {if($selected_top_category['id'] == $category['id'])}selected="selected"{/if}>{$category.name}</option>
                                    {/foreach}
                                </select>
                                <select name="category_id" data-am-selected="{btnWidth:'49%',btnSize:'md'}" id="sec_categories">
                                    {foreach $sec_categories as $category}
                                    <option value="{$category.id}" {if($selected_sec_category['id'] == $category['id'])}selected="selected"{/if}>{$category.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="name" class="am-u-sm-3 am-form-label">文档名称</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="name" name="name" placeholder="文档名称" value="{$info.name}" required>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="name" class="am-u-sm-3 am-form-label">是否发布</label>
                            <div class="am-u-sm-9">
                                <input type="checkbox" value="1" id="is_publish" name="is_publish" placeholder="是否发布" {if($info['is_publish'])}checked="checked"{/if}>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button type="submit" class="am-btn am-btn-primary">保存修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- content end -->
</div>

{include file='/public/footer'}
<script>
    $('#top_categories').on('change',function(e){
        $('#sec_categories').empty();
        var top_category_id = $(this).val();
        var url = "{:url('admin/category/ajax_get_sec_categories')}";
        var data = {top_category_id:top_category_id};
        $.ajax({
            url: url,
            data:data,
            success:function(res){
                if( res.code == 1 ){
                    var resultData = res.data;
                    for(key in resultData){
                        $('#sec_categories').append('<option value="'+resultData[key]['id']+'">'+resultData[key]['name']+'</option>');
                    }
                }
            },
            error:function(res){
                layer.msg('数据返回错误',{icon:2});
            }
        }).fail(function(){
            layer.msg('网络错误',{icon:2});
        });
    });
</script>